package com.sky.controller.admin;

import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

@RestController("adminShopController")
@Slf4j
@RequestMapping("/admin/shop")
@Api(tags = "管理端店铺相关接口")
public class ShopController {

    public static final String KEY="SHOP_STATUS";

    @Autowired
    private RedisTemplate redisTemplate;

    @PutMapping("/{status}")
    @ApiOperation("设置店铺的营业状态")
    public Result setStatus(@PathVariable Integer status){
        log.info("接收到的营业状态是:{}",status);
        //往redis存数据 找 redis就可以
        //调用 往redis中 存/修改 状态
        redisTemplate.opsForValue().set(KEY,status);

        return Result.success();
    }

    @GetMapping("/status")
    @ApiOperation("管理端获取店铺的营业状态")
    public Result<Integer> getStatus(){

        //从redis获取状态
        Integer status = (Integer) redisTemplate.opsForValue().get(KEY);
        log.info("管理端获取店铺的营业状态:"+status);
        return Result.success(status);
    }
}
